#   This file is part of emesene.
#
#    Eval plugin is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    Eval plugin is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with emesene; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

VERSION = '0.1'
import gtk
import Plugin
import TrayIcon
class MainClass(Plugin.Plugin):
    '''Main plugin class'''
    
    def __init__(self, controller, msn):
        '''Contructor'''
        Plugin.Plugin.__init__(self, controller, msn)
        
        self.description = _('Mute all sounds quickly through the systray menu')
        self.authors = { 'Guiman' : 'alvarola@gmail.com', \
                         'Nicolaide' : 'nicolasespina@gmail.com'}
        self.website = 'emesene.org'
        self.displayName = _('Mute Sounds')
        self.name = 'MuteSounds'
        self.controller = controller
        
        self.config = self.controller.config
        self.config.readPluginConfig(self.name)
        
        self.enabled = False
        
        self.checkBox = gtk.CheckMenuItem('Mute Sounds')
        self.checkBox.connect("toggled", self.muteSound, "checkMenuItem")
        
        
    def muteSound(self, widget, data=None):
        if widget.active:
        	self.disableSoundPlugin()
        else:
        	self.enableSoundPlugin()
        
    def updateTrayIconMenuList(self):
     	if not (TrayIcon.disabled) and self.enabled :
     		#Generates the Systray list with the new feature
     		#when the TrayIcon is enabled and also the plugin
            self.controller.trayIcon.menu.prepend(self.controller.trayDisconnect)
            self.controller.trayIcon.menu.prepend(self.controller.traySeparator)
            self.controller.trayIcon.menu.prepend(self.checkBox)
            self.controller.trayIcon.menu.prepend(self.controller.trayStatusMenu)
            self.controller.trayIcon.menu.show_all()
            self.controller.trayIcon.update(self.controller.msn.status)
        elif (not (TrayIcon.disabled) and not (self.enabled)):
            #Generates the Systray list without the new feature
     		#when the TrayIcon is enabled and the plugin not
        	self.controller.trayIcon.menu.remove(self.checkBox);
        	self.controller.trayIcon.menu.show_all()
        	self.controller.trayIcon.update(self.controller.msn.status)

        
    def start(self):
        '''start the plugin'''
        self.enabled = True
        self.updateTrayIconMenuList();

    def stop(self):    
        '''stop the plugin'''
        self.enabled = False
        self.updateTrayIconMenuList();
            
        
    def check(self):
        return (True, 'Ok')
        
    

    def disableSoundPlugin(self):
        soundPlugin = self.controller.pluginManager.getPlugin('Sound');
        if not(soundPlugin == 'None'):
            if soundPlugin.soundsEnabled :
                soundPlugin.enabled = False
        else:
            print 'No Sound plugin'
            
    def enableSoundPlugin(self):
        soundPlugin = self.controller.pluginManager.getPlugin('Sound');
        if not(soundPlugin == 'None'):
            if soundPlugin.soundsEnabled :
                soundPlugin.enabled = True
        else:
            print 'No Sound plugin'
